package com.cms.controller.front;

import com.cms.entity.Category;
import com.cms.entity.Model;
import com.cms.enums.ModelType;
import com.cms.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * Controller - 栏目
 * 
 * 
 * 
 */
@Slf4j
@Controller("frontCategoryController")
@RequestMapping("/category")
public class CategoryController extends BaseController {

	@Autowired
	private CategoryService categoryService;

	/**
	 * 栏目
	 */
	@RequestMapping
	public String index(Integer id,Integer pageNumber, ModelMap modelMap) {
		log.info("获取栏目信息...");
		Category category = categoryService.getById(id);
		modelMap.addAttribute("currentCategory", category);
		if(pageNumber==null){
			pageNumber = 1;
		}
		modelMap.addAttribute("pageNumber",pageNumber);
		Model model = category.getModel();
		if(model.getType() == ModelType.PAGE.ordinal()){
			return "/templates/"+getCurrentTemplate()+"/"+category.getDetailTemplate();
		}else{
			return "/templates/"+getCurrentTemplate()+"/"+category.getListTemplate();
		}
	}
}
